package zjl.graph;

import java.util.ArrayList;
import java.util.List;

public class Path implements BaseWeightedElement {

    private List<BaseVertex> vertexList = new ArrayList<>();
    private List<BaseEdge> edgeList = new ArrayList<>();

    // 路径权重值
    private double weight = 0.0;

    public Path() { }

    public Path(List<BaseVertex> vertexList, List<BaseEdge> edgeList, double weight) {
        this.vertexList = vertexList;
        this.edgeList = edgeList;
        this.weight = weight;
    }

    @Override
    public double getWeight() {
        return this.weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public List<BaseVertex> getVertexList() {
        return this.vertexList;
    }

    public List<BaseEdge> getEdgeList() {
        return this.edgeList;
    }

    public boolean containsVertex(BaseVertex vertex) {
        for (BaseVertex bv : this.vertexList) {
            if (bv.getId() == vertex.getId()) {
                return true;
            }
        }

        return false;
    }

    public boolean containsEdge(BaseEdge edge) {
        for (BaseEdge be : this.edgeList) {
            if (be.getId() == edge.getId()) {
                return true;
            }
        }

        return false;
    }

    @Override
    public boolean equals(Object that) {
        if (that instanceof Path) {
            Path t = (Path)that;
            return vertexList.equals(t.vertexList) && edgeList.equals(t.edgeList);
        }

        return false;
    }

    @Override
    public int hashCode() {
        return vertexList.hashCode() + edgeList.hashCode();
    }

    @Override
    public String toString() {
        return "VP=" + vertexList + " || EP=" + edgeList + " || WE=" + this.weight;
        //return this.vertexList.toString() + " = " + this.weight;
    }
}
